﻿<%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="Insert.aspx.cs"
    Inherits="ivvIncorporadoraInsert.Insert" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />
    <read>
<link href="../../../css/estilos.css" rel="stylesheet" type="text/css" />
</read>
    <h2>
        Cadastrar Incorporadora</h2>
    <br />
    <asp:Label runat="server" Text="" ID="lblValidacao" CssClass="textovermelho"></asp:Label>
    <br>
    <asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                HeaderText="Erros de validação:" />
            <asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="DetailsView1"
                Display="None" />
            <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="DetailsDataSource"
                DefaultMode="Insert" AutoGenerateInsertButton="False" OnItemCommand="DetailsView1_ItemCommand"
                OnItemInserted="DetailsView1_ItemInserted" CssClass="detailstable" FieldHeaderStyle-CssClass="bold"
                AutoGenerateDeleteButton="False" AutoGenerateRows="False">
                <FieldHeaderStyle CssClass="bold" />
                <Fields>
                    <asp:DynamicField DataField="razaoSocialIncorporadora" HeaderText="Razão social " />
                    <asp:DynamicField DataField="nomeContato1Incorporadora" HeaderText="Nome do contato 1 " />
                    <asp:DynamicField DataField="telefoneContato1Incorporadora" HeaderText="Telefone 1 " />
                    <asp:DynamicField DataField="emailContato1Incorporadora" HeaderText="Email 1 " />
                    <asp:DynamicField DataField="nomeContato2Incorporadora" HeaderText="Nome do contato 2 " />
                    <asp:DynamicField DataField="telefoneContato2Incorporadora" HeaderText="Telefone 2 " />
                    <asp:DynamicField DataField="emailContato2Incorporadora" HeaderText="Email 2 " />
                    <asp:DynamicField DataField="nomeContato3Incorporadora" HeaderText="Nome do contato 3 " />
                    <asp:DynamicField DataField="telefoneContato3Incorporadora" HeaderText="Telefone 3 " />
                    <asp:DynamicField DataField="emailContato3Incorporadora" HeaderText="Email 3 " />
                    <asp:DynamicField DataField="dataCadastroIncorporadora" HeaderText="Data de cadastro da incorporadora " />
                    <asp:DynamicField DataField="ativaIncorporadora" HeaderText="Ativa? " />
                    <asp:TemplateField ShowHeader="False">
                        <InsertItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Insert"
                                Text="Cadastrar" OnClientClick="return validar();"></asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                Text="Cancelar"></asp:LinkButton>
                        </InsertItemTemplate>
                    </asp:TemplateField>
                </Fields>
            </asp:DetailsView>
            <asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableInsert="true">
            </asp:LinqDataSource>

            <script language="javascript">

                function validar() {


                    for (i = 0; i < document.aspnetForm.elements.length; i++) {

                        //localizar o nome do campo de nome do usuário

                        var encontrouDesc = document.aspnetForm.elements[i].name.indexOf("razaoSocialIncorporadora");

                        if (encontrouDesc >= 0) {

                            //validar

                            if (document.aspnetForm.elements[i].value == "") {

                                alert('A razão social deve ser informada.');
                                document.aspnetForm.elements[i].focus();
                                return false;

                                // Fim segundo IF
                            }
                            //Fim primeiro IF
                        }
                        //Fim do FOR 1
                    }





                    for (i = 0; i < document.aspnetForm.elements.length; i++) {

                        //localizar o nome do campo do tipo do usuário (obs: combobox)

                        var encontrouDesc = document.aspnetForm.elements[i].name.indexOf("nomeContato1Incorporadora");
                        var encontrouDesc2 = document.aspnetForm.elements[i].name.indexOf("nomeContato2Incorporadora");
                        var encontrouDesc3 = document.aspnetForm.elements[i].name.indexOf("nomeContato3Incorporadora");

                        if (encontrouDesc >= 0 || encontrouDesc2 >= 0 || encontrouDesc3 >= 0) {

                            //validar

                            if (document.aspnetForm.elements[i].value == 0) {

                                alert('Informe ao menos um nome de contato');
                                document.aspnetForm.elements[i].focus();
                                return false;

                                // Fim segundo IF
                            }
                            //Fim primeiro IF
                        }
                        //Fim do FOR 2
                    }
                    //Fim da função validar  
                }
                // Fim do script
            </script>

        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
